<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<body>


  new function  用来检测js错误 可以替代eval() 字符串转js代码检查  字符串编译解析成js指向Function，防止有些前端编译工具报错


<script>
    var stringScript=` function random(min, max) {
        return min + Math.floor((max - min + 1) * Math.random());
    }

     //实例化对象
    var CalculatorChannel = new MessageChannel();

    var newsOne = CalculatorChannel.port1; //端口1
    var newsTow = CalculatorChannel.port2; //端口2


    newsOne.onmessage = function(event) {
        //console.log("port1收到来自port2的数据：" + event.data);
        var d = event.data;
        console.log('num1: ' + d.num1, 'num2: ' + d.num2);
        var sum = d.num1 + d.num2;
        //推送信息 更新  newsTow 推送信息 像消息体2推送信息
         newsOne.postMessage(sum)
    }



    newsTow.onmessage = function(event) {
        //console.log("port2收到来自port1的数据：" + event.data);
        console.log('结果为：' + event.data);
    }`
    console.log(new Function(("return " + stringScript)));
</script>



</body>
</html>
